/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package PathModel;

import java.util.LinkedList;
import java.util.List;
import java.util.Iterator;

/**
 *
 * @author Alwyn
 */
public class PathProfile {

    List<PathPoint> mPath=new LinkedList<PathPoint>();
    EarthModel mEarth;
    double dTxAntennaHeight;
    double dRxAntennaHeight;

    public PathProfile()
    {
        mPath.clear();
        mEarth=new SphericalEarth(); // Default to spherical earth
    }

    public void setEarthModel(EarthModel m)
    {
        mEarth=m;
    }

    public EarthModel getEarthModel()
    {
        return mEarth;
    }

    public int size()
    {
        return mPath.size();
    }

    public double getLength()
    {
        if(mPath.size()==0)
            return 0;
        
        return mPath.get(size()-1).dDistance;
    }

    public void initiatePath(Location tx, Location rx, int n)
    {
        mPath.clear();
        mPath.add(new PathPoint(tx,0,0));

        double distance=mEarth.getDistance(tx, rx);
        double bearing=mEarth.getInitialBearing(tx, rx);

        for(int i=0; i<n;i++)
        {
            double dd=((i+1)/(n+1))*distance;
            Location p=mEarth.getPointLocation(tx, dd, bearing);

            mPath.add(new PathPoint(p,0,dd));
        }

        mPath.add(new PathPoint(rx,0,distance));
    }

    public void initiatePath(Location tx, Location rx)
    {
        double distance=mEarth.getDistance(tx, rx);

        int n=(int)distance+1; // Minimum diatance should be 1km

        initiatePath(tx, rx, n);
    }

    public void initiatePath(Location tx, Location rx, double maxInterval)
    {
        // maxInterval is the maximum distance between points
        double distance=mEarth.getDistance(tx, rx);
        
        int n=(int)(distance/maxInterval);
        
        initiatePath(tx, rx, n);
    }

    public Iterator getPathIterator()
    {
        return mPath.iterator();
    }

    // Antenna height above GROUND, not sea level
    public void setTxAntennaHeight(double dTxHeight)
    {
        dTxAntennaHeight=dTxHeight;
    }

    public double getTxAntennaHeight()
    {
        return dTxAntennaHeight;
    }

    public void setRxAntennaHeight(double dRxHeight)
    {
        dRxAntennaHeight=dRxHeight;
    }

    public double getRxAntennaHeight()
    {
        return dRxAntennaHeight;
    }

}
